/*
 * Created on 2005-9-1
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.store;

import java.util.ArrayList;
import java.util.List;

import com.jedi.BaseObj;
import com.tss.util.DbConn;
import com.tss.util.DbRs;

/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class TaskDetailMgr extends BaseObj {
	public TaskDetailMgr() {}
	
	public TaskDetail get(String id) {
		clearErr();
		TaskDetail detail = new TaskDetail(id);
		DbConn conn = new DbConn();
		try {
			String sql = "";
			sql = "select * from taskdetail where partid = ?";
			conn.prepare(sql);
			conn.setString(1,id);
			DbRs rs = conn.executeQuery();
			if (rs == null || rs.size() ==0) return null;
			detail.setTaskId(getInt(rs,0,"taskid"));
			detail.setRevPartNo(get(rs,0,"rev_artno"));
			detail.setSerialNo(get(rs,0,"serialno"));
			detail.setContextFile(get(rs,0,"contextfile"));
			detail.setContextDesc(get(rs,0,"contextdesc"));
			detail.setOutPartNo(get(rs,0,"outpartno"));
			detail.setOutSerialNo(get(rs,0,"outserialno"));
			return detail;
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return null;
		}
		finally {
			conn.close();
		}
	}
	
	public List get(String otherSQL,String orderField) {
		clearErr();
		DbConn conn = new DbConn();
		DbRs rs = null;
		try {
			String sql = "";
			sql = "select * from taskdetail where 1=1";
			if (otherSQL != null && !otherSQL.trim().equals("")) 
				sql += otherSQL;
			if (orderField != null && !orderField.trim().equals(""))
				sql += " order by " + orderField;
			conn.prepare(sql);
			rs = conn.executeQuery();
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return null;
		}
		finally {
			conn.close();
		}
		if (rs != null && rs.size() >0) {
			List r = new ArrayList();
			for(int i=0;i<rs.size();i++) {
				TaskDetail detail = new TaskDetail(get(rs,i,"listid"));
				detail.setTaskId(getInt(rs,i,"taskid"));
				detail.setRevPartNo(get(rs,i,"revpartno"));
				detail.setSerialNo(get(rs,i,"serialno"));
				detail.setContextFile(get(rs,i,"contextfile"));
				detail.setContextDesc(get(rs,i,"contextdesc"));
				detail.setOutPartNo(get(rs,i,"outpartno"));
				detail.setOutSerialNo(get(rs,i,"outserialno"));
				r.add(detail);
			}
			return r;
		}
		return null;
	}
}
